/*
 * @Autor: Shihh
 * @Description: 
 * @Version: 1.0
 * @Date: 2020-05-08 10:06:22
 * @LastEditors: Shihh
 * @LastEditTime: 2020-05-08 17:56:01
 */
const Sequelize = require('sequelize')



module.exports = (sequelize, DataTypes ) =>{

    class topicRelation extends Sequelize.Model{
        //获取专题 
        static async gettopicInner(id){
            var querydata=[]
            let condition = {
                attributes: ['id','topic_id','associated_id','tp_type'],
                raw:true,
                where:{
                    topic_id:id
                }
            }
            querydata = await this.findAll(condition)
            return querydata;
        }
    }

    topicRelation.init({
        id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
        topic_id: { type: DataTypes.INTEGER },
        associated_id: { type: DataTypes.INTEGER },
        tp_type: { type: DataTypes.INTEGER, defaultValue:0 },
      }, {
        sequelize,
        modelName: 'topic_relation',
        freezeTableName: true,
        timestamps: false
      });
    
      return topicRelation;

}

